package com.awspaas.user.apps.shhtaerospaceindustrial.guaranteecar;

import com.actionsoft.bpms.bo.engine.BO;
import com.actionsoft.bpms.bpmn.engine.core.delegate.ProcessExecutionContext;
import com.actionsoft.bpms.bpmn.engine.listener.ExecuteListener;
import com.actionsoft.bpms.commons.database.ColumnMapRowMapper;
import com.actionsoft.bpms.commons.mvc.view.ResponseObject;
import com.actionsoft.bpms.util.DBSql;
import com.actionsoft.sdk.local.SDK;
import com.actionsoft.sdk.local.api.BOAPI;
import java.util.List;
import java.util.Map;

public class createUnitBzCarlist extends ExecuteListener {
    @Override
	public String getDescription() {
        return "表单加载前事件";
    }
    @Override
	public String getProvider() {
        return "dingyi";
    }
    @Override
	public String getVersion() {
        return "1.0";
    }


	@Override
	public void execute(ProcessExecutionContext param) throws Exception {
        // TODO Auto-generated method stub
        ResponseObject respon = ResponseObject.newOkResponse();
        String unitshortnaem=param.getUserContext().getCompanyModel().getExt2();
        String bindid = param.getProcessInstance().getId();
        
        String querySql1 = "select CARNO,CARTYPE from BO_EU_BZYC_CARSTOPBODY where bindid='" + bindid + "'";
        List<Map<String, Object>> dataList = DBSql.query(querySql1, new ColumnMapRowMapper());
        if (dataList != null && !dataList.isEmpty())
        {
        	
        }else {
        	
            String queryunitcars = "SELECT VEHICLETYPE,VEHICLECODE FROM BO_EU_BZYC_CARDDOCINFO WHERE CARGROUPID = '" + unitshortnaem + "' and  CARSTATIUS !='报废'";

            List<Map<String, Object>> cardataList = DBSql.query(queryunitcars, new ColumnMapRowMapper());
            for (Map<String, Object> dataMap : cardataList) {
//				JSONObject orderItem = new JSONObject();
                String VEHICLECODE = objToStr(dataMap.get("VEHICLECODE"));
                String VEHICLETYPE = objToStr(dataMap.get("VEHICLETYPE"));
                
                BOAPI boAPI = SDK.getBOAPI();
                String boname = "BO_EU_BZYC_CARSTOPBODY"; //��λ��������
                BO boRecordData = new BO();
                boRecordData.set("CARNO", VEHICLECODE);
                boRecordData.set("CARTYPE", VEHICLETYPE);
               
                int actionflag = boAPI.create(boname, boRecordData, param.getProcessInstance(), param.getUserContext());

                
                }
        	
        	
        }
//		respon.put("action", "success");

//	return"Sucesss";
	}

	public static String objToStr(Object obj) {
		return obj == null ? "" : obj.toString();
	}

}
